package com.cicada.cocos2dsamples.samples;

import org.cocos2d.layers.CCLayer;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.nodes.CCSprite;
import org.cocos2d.types.CGSize;

public class Acceleration extends BaseActivity {

	@Override
	public CCLayer getLayer() {
		return new Layer();
	}

	class Layer extends CCLayer {
		public CGSize winSize = CCDirector.sharedDirector().winSize();
		private float baseX = 0;
		private float baseY = 0;
		private boolean isAccelFirst;
		CCSprite block;

		public Layer() {
			setIsAccelerometerEnabled(true);
			block = CCSprite.sprite("blocks.png");
			block.setPosition(winSize.getWidth() / 2, winSize.getHeight() / 2);
			addChild(block);
			isAccelFirst = true;
		}

		@Override
		public void ccAccelerometerChanged(float accelX, float accelY,
				float accelZ) {
			super.ccAccelerometerChanged(accelX, accelY, accelZ);
			if (isAccelFirst) {
				isAccelFirst = !isAccelFirst;
				baseX = accelX;
				baseY = accelY;
			}
		}
	}

}
